function MenuApp(){
    this.submitUrl = '/cooker.php?m=cooker&c=menu&a=submitMenu';
    this.lockStatus = 1;
}
MenuApp.prototype = {

    init:function(){
        //显示套餐列表
        MenuApp.prototype.showMenuList();
    },

    showMenuList:function(){
        var parser = MenuApp.prototype.parser;
        var nosend = MenuApp.prototype.nosend;
        var tpl = $('#menuTpl').html();
        //全部菜单
        var apiUrl = '/cooker.php?m=cooker&c=Menu&a=menuList';
        $.get(apiUrl,function(data){
            //载入模版并创建数据
            if(data.data.length >0){
                parser('allMenus',data,tpl);
            }else{
                nosend();
            }

        });
    },
    showMenu:function(){
        var apiUrl = '/cooker.php?m=cooker&c=Menu&a=ajax_menu';
        $.get(apiUrl,function(data){
            if(data.status == 1){
                $('#menu').text(data.data);
            }else{
                mui.alert(data.message, '温馨提示', function() {
                   window.location.href="/cooker.php?m=cooker&c=Menu&a=index"
                });
            }
        });
    },
    showDish:function(){
        var apiUrl = '/cooker.php?m=cooker&c=Menu&a=dishList';
        var menu_id = $('#menu_id').val();
        $.get(apiUrl,{id:menu_id},function(data){
            if(data.status == 1){
                $('#menu').text(data.data);
            }else{
                mui.alert(data.message, '温馨提示', function() {
                    window.location.href="/cooker.php?m=cooker&c=Menu&a=index"
                });
            }
        });
    },
    nosend:function () {
        var html = '<div style="text-align: center">还没有菜单，快新增吧</div>';
        $('#allMenus').show();
        $('#allMenus').append(html);
    },
    //juicer载入数据,混合模板一体化
    parser:function(id,data,tpl,mode){
        //载入模版
        var id = '#'+id;
        if(!tpl){
            if(mode != 'update'){
                tpl = $(id).html();
            }else{
                tpl = $(id).attr('data-tpl');
            }
        }
        var html = juicer(tpl,data);
        $(id).html(html).show().attr('data-tpl',tpl);
    },
    addInput:function(){
        var tpl = $('#add_input_tpl').html();
        $('#input_list').append(tpl);
    },
    submitMenu:function(){
        var menu = $('#menu').text();
        var caipin = [$('#input_list .menu_list.first').val()];
        $('#input_list .menu_list.normal').each(function(index){
            caipin.push($(this).val());
        });
        var price = $('#menu_price .price').val();
        var obj = {
            menu:menu,
            caipin:caipin,
            price : price
        };
        console.log(obj);
        this.load_lock(1);
        $.post(this.submitUrl,obj,function(data){
            if(data.status == 1){
                mui.alert(data.message, '温馨提示', function() {
                    window.location.href="/cooker.php?m=cooker&c=Menu&a=index"
                });
            }else{
                mui.alert(data.message, '温馨提示', function() {
                    window.location.href="/cooker.php?m=cooker&c=Menu&a=index"
                });
            }

        });


    },
    load_lock:function($status){
        if($status === 1){
            //加载动画开启

            this.lockStatus = 0;
        }
        else{
            //加载动画消失

            this.lockStatus = 1;
        }
    }

};
